package com.jprocms.module.cms.controller.admin.investigateitemop;

import com.jpro.framework.common.pojo.CommonResult;
import com.jpro.framework.common.pojo.PageResult;
import com.jprocms.module.cms.controller.admin.investigateitemop.vo.InvestigateItemOpCreateReqVO;
import com.jprocms.module.cms.controller.admin.investigateitemop.vo.InvestigateItemOpPageReqVO;
import com.jprocms.module.cms.controller.admin.investigateitemop.vo.InvestigateItemOpRespVO;
import com.jprocms.module.cms.controller.admin.investigateitemop.vo.InvestigateItemOpUpdateReqVO;
import com.jprocms.module.cms.convert.investigateitemop.InvestigateItemOpConvert;
import com.jprocms.module.cms.dal.dataobject.investigateitemop.InvestigateItemOpDO;
import com.jprocms.module.cms.service.investigate.InvestigateItemOpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static com.jpro.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 调查问卷条目意见")
@RestController
@RequestMapping("/cms/investigate-item-op")
@Validated
public class InvestigateItemOpController {

    @Resource
    private InvestigateItemOpService investigateItemOpService;

    @PostMapping("/create")
    @Operation(summary = "创建调查问卷条目意见")
    @PreAuthorize("@ss.hasPermission('cms:investigate:create')")
    public CommonResult<Long> createInvestigateItemOp(@Valid @RequestBody InvestigateItemOpCreateReqVO createReqVO) {
        return success(investigateItemOpService.createInvestigateItemOp(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新调查问卷条目意见")
    @PreAuthorize("@ss.hasPermission('cms:investigate:update')")
    public CommonResult<Boolean> updateInvestigateItemOp(@Valid @RequestBody InvestigateItemOpUpdateReqVO updateReqVO) {
        investigateItemOpService.updateInvestigateItemOp(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除调查问卷条目意见")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('cms:investigate:delete')")
    public CommonResult<Boolean> deleteInvestigateItemOp(@RequestParam("id") Long id) {
        investigateItemOpService.deleteInvestigateItemOp(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得调查问卷条目意见")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('cms:investigate:query')")
    public CommonResult<InvestigateItemOpRespVO> getInvestigateItemOp(@RequestParam("id") Long id) {
        InvestigateItemOpDO investigateItemOp = investigateItemOpService.getInvestigateItemOp(id);
        return success(InvestigateItemOpConvert.INSTANCE.convert(investigateItemOp));
    }

    @GetMapping("/list")
    @Operation(summary = "获得调查问卷条目意见列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('cms:investigate:query')")
    public CommonResult<List<InvestigateItemOpRespVO>> getInvestigateItemOpList(@RequestParam("ids") Collection<Long> ids) {
        List<InvestigateItemOpDO> list = investigateItemOpService.getInvestigateItemOpList(ids);
        return success(InvestigateItemOpConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得调查问卷条目意见分页")
    @PreAuthorize("@ss.hasPermission('cms:investigate:query')")
    public CommonResult<PageResult<InvestigateItemOpRespVO>> getInvestigateItemOpPage(@Valid InvestigateItemOpPageReqVO pageVO) {
        PageResult<InvestigateItemOpDO> pageResult = investigateItemOpService.getInvestigateItemOpPage(pageVO);
        return success(InvestigateItemOpConvert.INSTANCE.convertPage(pageResult));
    }

}
